/**
 * Simple regex experiment to create an automatic emoticons by Keiruchan
 * Visit: http://ad1tweb.blogspot.com
 * Update: 27 September 2012
 */

$(function() {

	// Append an emoticon bar before comment-form
	if (putEmoAbove) {
		$(putEmoAbove).before('<div class="emoWrap"> :) :( =( :waaa: :s ^_^ :D =D ^:D @@, ;) :-bd :-d :yaya: :&#39;( T_T :&#92; :p B) :Q :Ozz 7:( &#92;o/ &#92;m/ **p &lt;3 0:) ^o^ :-a 7:O *fck* xV x@ X@ ~x( &lt;:) &lt;=) (-.-,) *=p =p* &#39;&#39;J :W :bye: :imhere: :cendol: :rolled: *bang* :drummer: :guitarist: :vocalist:</div>');
	}
	function emo(emo, imgRep, emoKey) {
		$(emoRange).each(function() {
			$(this).html($(this).html()
			.replace(/<br>(:|;|=|\^)/g, "<br> $1")
			.replace(emo, " <img src='" + imgRep + "' class='emo delayLoad' alt='" + emoKey + "' />"));
		});
	}
	emo(/\s:\)+/g, "http://reader-download.googlecode.com/svn/trunk/images/emo/smile.gif", ":)");
	emo(/\s;\)+/g, "http://reader-download.googlecode.com/svn/trunk/images/emo/wink.gif", ";)");
	emo(/\s:\(/g, "http://reader-download.googlecode.com/svn/trunk/images/emo/sad.gif", ":(");
	emo(/\s=\(/g, "http://reader-download.googlecode.com/svn/trunk/images/emo/sadanimated.gif", "=(");
	emo(/\s@@,/g, "http://reader-download.googlecode.com/svn/trunk/images/emo/rolleyes.gif", "@@,");
	emo(/\s:yaya:/ig, "http://reader-download.googlecode.com/svn/trunk/images/emo/yaya.gif", ":yaya:");
	emo(/\s:s/ig, "http://reader-download.googlecode.com/svn/trunk/images/emo/sullen.gif", ":s");
	emo(/\s:\\/g, "http://reader-download.googlecode.com/svn/trunk/images/emo/memble.gif", ":&#92;");
	emo(/\s:D/g, "http://reader-download.googlecode.com/svn/trunk/images/emo/haha.gif", ":D");
	emo(/\s=D/g, "http://reader-download.googlecode.com/svn/trunk/images/emo/hihi.gif", "=D");
	emo(/\s\^:D/g, "http://reader-download.googlecode.com/svn/trunk/images/emo/abovemehaha.gif", "^:D");
	emo(/\s\^(\_|)\^/g, "http://reader-download.googlecode.com/svn/trunk/images/emo/senyum-tulus.gif", "^_^");
	emo(/\s:'\(/g, "http://reader-download.googlecode.com/svn/trunk/images/emo/cry.gif", ":&#39;(");
	emo(/\s:waaa:/g, "http://reader-download.googlecode.com/svn/trunk/images/emo/wawa.gif", ":waaa:");
	emo(/\sT_T/ig, "http://reader-download.googlecode.com/svn/trunk/images/emo/tears.gif", "T_T");
	emo(/\sB\)/g, "http://reader-download.googlecode.com/svn/trunk/images/emo/cool.gif", "B)");
	emo(/\s:Q/ig, "http://reader-download.googlecode.com/svn/trunk/images/emo/smoking.gif", ":Q");
	emo(/\s\*\*p/ig, "http://reader-download.googlecode.com/svn/trunk/images/emo/crazy.gif", "**p");
	emo(/\s7:\(/g, "http://reader-download.googlecode.com/svn/trunk/images/emo/conf.gif", "7:(");
	emo(/\s:p/ig, "http://reader-download.googlecode.com/svn/trunk/images/emo/wee.gif", ":p");
	emo(/\s:Oz+/ig, "http://reader-download.googlecode.com/svn/trunk/images/emo/sleep.gif", ":Ozz");
	emo(/\s7:O/ig, "http://reader-download.googlecode.com/svn/trunk/images/emo/angry.gif", "7:O");
	emo(/\s\\o\//ig, "http://reader-download.googlecode.com/svn/trunk/images/emo/applause.gif", "&#92;o/");
	emo(/\s\\m\//ig, "http://reader-download.googlecode.com/svn/trunk/images/emo/metal.gif", "&#92;m/");
	emo(/\s&lt;3/ig, "http://reader-download.googlecode.com/svn/trunk/images/emo/love.gif", "&amp;amp;lt;3");
	emo(/\s0:\)+/ig, "http://reader-download.googlecode.com/svn/trunk/images/emo/angelgreen.gif", "0:)");
	emo(/\s\^o\^/ig, "http://reader-download.googlecode.com/svn/trunk/images/emo/angelwhite.gif", "^o^");
	emo(/\s:-a/ig, "http://reader-download.googlecode.com/svn/trunk/images/emo/vomit.gif", ":-a");
	emo(/\s\*fck\*/ig, "http://reader-download.googlecode.com/svn/trunk/images/emo/fuck.gif", "*fck*");
	emo(/\sxV/ig, "http://reader-download.googlecode.com/svn/trunk/images/emo/demo.gif", "xV");
	emo(/\sx\@/g, "http://reader-download.googlecode.com/svn/trunk/images/emo/marahbesar.gif", "x@");
	emo(/\s\X\@/g, "http://reader-download.googlecode.com/svn/trunk/images/emo/arrgh.gif", "X@");
	emo(/\s:-d/ig, "http://reader-download.googlecode.com/svn/trunk/images/emo/top.gif", ":-d");
	emo(/\s:-bd/ig, "http://reader-download.googlecode.com/svn/trunk/images/emo/topmarkotop.gif", ":-bd");
	emo(/\s\~x\(+/ig, "http://reader-download.googlecode.com/svn/trunk/images/emo/ugh.gif", "~x(");
	emo(/\s:bye:/ig, "http://reader-download.googlecode.com/svn/trunk/images/emo/bye.gif", ":bye:");
	emo(/\s:W/g, "http://reader-download.googlecode.com/svn/trunk/images/emo/explain.gif", ":W");
	emo(/\s\(-\.-,\)/g, "http://reader-download.googlecode.com/svn/trunk/images/emo/pumpkin.gif", "(-.-,)");
	emo(/\s\*=p/ig, "http://reader-download.googlecode.com/svn/trunk/images/emo/ball1.gif", "*=p");
	emo(/\s=p\*/ig, "http://reader-download.googlecode.com/svn/trunk/images/emo/ball2.gif", "=p*");
	emo(/\s:imhere:/ig, "http://reader-download.googlecode.com/svn/trunk/images/emo/imhere.gif", ":imhere:");
	emo(/\s:cendol:/ig, "http://reader-download.googlecode.com/svn/trunk/images/emo/cendol.gif", ":cendol:");
	emo(/\s&lt;:\)/ig, "http://reader-download.googlecode.com/svn/trunk/images/emo/festival1.gif", "&amp;amp;lt;:)");
	emo(/\s&lt;=\)/ig, "http://reader-download.googlecode.com/svn/trunk/images/emo/festival2.gif", "&amp;amp;lt;=)");
	emo(/\s:rolled:/ig, "http://reader-download.googlecode.com/svn/trunk/images/emo/rolled.gif", ":rolled:");
	emo(/\s\*bang\*/ig, "http://reader-download.googlecode.com/svn/trunk/images/emo/bang.gif", "*bang*");
	emo(/\s\'\'J/ig, "http://reader-download.googlecode.com/svn/trunk/images/emo/call.gif", "&#39;&#39;J");
	emo(/\s:drummer:/ig, "http://reader-download.googlecode.com/svn/trunk/images/emo/drummer.gif", ":drummer:");
	emo(/\s:guitarist:/ig, "http://reader-download.googlecode.com/svn/trunk/images/emo/guitarist.gif", ":guitarist:");
	emo(/\s:vocalist:/ig, "http://reader-download.googlecode.com/svn/trunk/images/emo/vocalist.gif", ":vocalist:");

	// Show alert one times!
	$('.emoWrap').one("click", function() {
		if(emoMessage) {
			alert(emoMessage);
		}
	});
	// Click to show the code!
	$('.emo').css('cursor', 'pointer').live("click", function(e) {
		$('.emoKey').remove();
		$(this).after('<input class="emoKey" type="text" size="6" value=" ' + this.alt + '" />');
		$('.emoKey').trigger("select");
		e.stopPropagation();
	});
	$(document).on("click", function() {
		$('.emoKey').remove();
	});

});
